﻿/**
* @description  Class to hold basic properties for a slideshow and pages, like dimensions and background color.
*/
package com.foed.applications.slideshow {
	
	import com.foed.animation.TweenComposite;

	public class SlideProperties {

		static public const TIME:String = "time";
		static public const BG_COLOR:String = "bgColor";
		static public const TRANSITION:String = "transition";

		private var _width:Number;
		private var _height:Number;
		private var _xml:XML;
		
		/**
		* @description  Constructor.
		*
		* @param  pWidth  The width of the slideshow in pixels.
		* @param  pHeight  The height of the slideshow in pixels.
		*/
		public function SlideProperties(
			pWidth:Number,
			pHeight:Number
		) {
			_width = pWidth;
			_height = pHeight;
		}
		
		/**
		* @description  Populates the instance with values from XML.
		*
		* @param  pXML  The XML defining the slideshow and slide properties.
		*/
		public function populate(pXML:XML):void {
			_xml = pXML;
		}
		
		/**
		* @description  Returns the value for the specified property, if it exists.
		*
		* @param  pProperty  The name of the property with the value to retrieve.
		*
		* @returns  The value for the specified property, if it exists.
		*/
		public function getProperty(pProperty:String):String {
			if (_xml == null) return null;
			return _xml.@[pProperty];
		}
		
		/**
		* @description  Returns a SlideProperties instance populated for a specific slide.
		*
		* @param  pSlideType  The node name for the slide to receive a SlideProperties instance.
		*
		* @returns  A SlideProperties instance populated for a specific slide.
		*/
		public function getChildSlideProperties(pSlideType:String):SlideProperties {
			var pProperties:SlideProperties = new SlideProperties(_width, _height);
			pProperties.populate(_xml.child(pSlideType)[0]);
			return pProperties;
		}

		/**
		* @description  Returns the pixel width stored in the instance.
		*
		* @returns  The pixel width stored in the instance.
		*/
		public function get width():Number {
			return _width;
		}

		/**
		* @description  Returns the pixel height stored in the instance.
		*
		* @returns  The pixel height stored in the instance.
		*/
		public function get height():Number {
			return _height;
		}

		/**
		* @description  Returns the transition data stored in the instance.
		*
		* @returns  The transition data stored in the instance.
		*/
		public function get transition():XMLList {
			if (_xml == null) return new XMLList();
			return _xml.child(TRANSITION);
		}

	}

}